
NAME		= it87
VERSION		= 2.10.1
DISTDIR		= $(NAME)-$(VERSION)
DISTFILE	= $(DISTDIR).tar.gz
KMODTOOL	= kmodtool
SPECFILE	= it87-kmod.spec

RPM_ROOT	?= ~/rpmbuild

KDIR		?= /lib/modules/$(shell uname -r)/build

obj-$(CONFIG_SENSORS_IT87) += it87.o

all:		module

module:		it87.ko

it87.ko:	it87.c
	make -C $(KDIR)    M=`pwd` modules

moduleinstall:	it87.ko
	make -C $(KDIR)    M=`pwd` INSTALL_MOD_DIR=extra/$(NAME) modules_install

moduleclean:
	make -C $(KDIR) -r M=`pwd` clean

spec:		$(SPECFILE)

$(SPECFILE):	$(SPECFILE).in
	sed -e "s,@VERSION@,$(VERSION)," $< > $@

dist:		$(DISTFILE)

$(DISTFILE):	Makefile Kconfig it87.c $(SPECFILE).in modprobe.conf*
	rm -f $@
	rm -rf $(DISTDIR)
	mkdir $(DISTDIR)
	cp $^ $(DISTDIR)
	tar zcf $@ $(DISTDIR)
	rm -rf $(DISTDIR)

clean:		moduleclean
	rm -f Module.symvers $(SPECFILE)

distclean:	clean
	rm -f $(DISTFILE)

rpmprep:	$(DISTFILE) $(SPECFILE) $(KMODTOOL)
	cp $(KMODTOOL) $(DISTFILE) $(RPM_ROOT)/SOURCES
#	cp $(SPECFILE)             $(RPM_ROOT)/SPECS

srpm:		rpmprep
	if [ -z "$(KVARIANTS)" ]; then		\
		rpmbuild -bs $(SPECFILE) ;	\
	else					\
		rpmbuild --define 'kvariants $(KVARIANTS)' -bs $(SPECFILE) ;	\
	fi

rpm:		rpmprep
#	rm -f $(RPM_ROOT)/RPMS/x86_64/*it87* 
	@if [ -z "$(KVARIANTS)" ]; then		\
		rpmbuild -ba $(SPECFILE) ;	\
	else					\
		rpmbuild --define 'kvariants $(KVARIANTS)' -ba $(SPECFILE) ;	\
	fi

